//
//  ONDayAHeadObjects.m
//
//  Created by Chinh.X.Bui  on 6/4/14
//  Copyright (c) 2014 __MyCompanyName__. All rights reserved.
//

#import "ONDayAHeadObjects.h"


NSString *const kONDayAHeadObjectsDeliverydate = @"deliverydate";
NSString *const kONDayAHeadObjectsLmp = @"lmp";
NSString *const kONDayAHeadObjectsCongestion = @"congestion";
NSString *const kONDayAHeadObjectsPowerpoint = @"powerpoint";
NSString *const kONDayAHeadObjectsLoss = @"loss";
NSString *const kONDayAHeadObjectsHourending = @"hourending";


@interface ONDayAHeadObjects ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ONDayAHeadObjects

@synthesize deliverydate = _deliverydate;
@synthesize lmp = _lmp;
@synthesize congestion = _congestion;
@synthesize powerpoint = _powerpoint;
@synthesize loss = _loss;
@synthesize hourending = _hourending;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.deliverydate = [self objectOrNilForKey:kONDayAHeadObjectsDeliverydate fromDictionary:dict];
            self.lmp = [[self objectOrNilForKey:kONDayAHeadObjectsLmp fromDictionary:dict] doubleValue];
            self.congestion = [[self objectOrNilForKey:kONDayAHeadObjectsCongestion fromDictionary:dict] doubleValue];
            self.powerpoint = [self objectOrNilForKey:kONDayAHeadObjectsPowerpoint fromDictionary:dict];
            self.loss = [[self objectOrNilForKey:kONDayAHeadObjectsLoss fromDictionary:dict] doubleValue];
            self.hourending = [[self objectOrNilForKey:kONDayAHeadObjectsHourending fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.deliverydate forKey:kONDayAHeadObjectsDeliverydate];
    [mutableDict setValue:[NSNumber numberWithDouble:self.lmp] forKey:kONDayAHeadObjectsLmp];
    [mutableDict setValue:[NSNumber numberWithDouble:self.congestion] forKey:kONDayAHeadObjectsCongestion];
    [mutableDict setValue:self.powerpoint forKey:kONDayAHeadObjectsPowerpoint];
    [mutableDict setValue:[NSNumber numberWithDouble:self.loss] forKey:kONDayAHeadObjectsLoss];
    [mutableDict setValue:[NSNumber numberWithDouble:self.hourending] forKey:kONDayAHeadObjectsHourending];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.deliverydate = [aDecoder decodeObjectForKey:kONDayAHeadObjectsDeliverydate];
    self.lmp = [aDecoder decodeDoubleForKey:kONDayAHeadObjectsLmp];
    self.congestion = [aDecoder decodeDoubleForKey:kONDayAHeadObjectsCongestion];
    self.powerpoint = [aDecoder decodeObjectForKey:kONDayAHeadObjectsPowerpoint];
    self.loss = [aDecoder decodeDoubleForKey:kONDayAHeadObjectsLoss];
    self.hourending = [aDecoder decodeDoubleForKey:kONDayAHeadObjectsHourending];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_deliverydate forKey:kONDayAHeadObjectsDeliverydate];
    [aCoder encodeDouble:_lmp forKey:kONDayAHeadObjectsLmp];
    [aCoder encodeDouble:_congestion forKey:kONDayAHeadObjectsCongestion];
    [aCoder encodeObject:_powerpoint forKey:kONDayAHeadObjectsPowerpoint];
    [aCoder encodeDouble:_loss forKey:kONDayAHeadObjectsLoss];
    [aCoder encodeDouble:_hourending forKey:kONDayAHeadObjectsHourending];
}

- (id)copyWithZone:(NSZone *)zone
{
    ONDayAHeadObjects *copy = [[ONDayAHeadObjects alloc] init];
    
    if (copy) {

        copy.deliverydate = [self.deliverydate copyWithZone:zone];
        copy.lmp = self.lmp;
        copy.congestion = self.congestion;
        copy.powerpoint = [self.powerpoint copyWithZone:zone];
        copy.loss = self.loss;
        copy.hourending = self.hourending;
    }
    
    return copy;
}


@end
